package com.chuyu.cy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chuyu.cy.contants.ResponseCodeEnum;
import com.chuyu.cy.entity.domain.TemporaryNeedsKinds;
import com.chuyu.cy.entity.vo.NeedsKindVo;
import com.chuyu.cy.exception.CustomException;
import com.chuyu.cy.mapper.TemporaryNeedsKindsMapper;
import com.chuyu.cy.service.TemporaryNeedsKindsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 周小白
* @description 针对表【temporary_needs_kinds(临时需求种类表)】的数据库操作Service实现
*/
@Service
public class TemporaryNeedsKindsServiceImpl extends ServiceImpl<TemporaryNeedsKindsMapper, TemporaryNeedsKinds>
    implements TemporaryNeedsKindsService{

    @Resource
    private TemporaryNeedsKindsMapper temporaryNeedsKindsMapper;



    /**
     * 获取需求种类列表
     * @return 需求种类列表
     */
    @Override
    public List<NeedsKindVo> getNeedsKindList() {

        List<TemporaryNeedsKinds> needsKindsList = temporaryNeedsKindsMapper.selectList(null);

        if (needsKindsList == null || needsKindsList.isEmpty()) {
            throw new CustomException(ResponseCodeEnum.SYSTEM_ERROR);
        }

        ArrayList<NeedsKindVo> needsKindVos = new ArrayList<>();

        needsKindsList.forEach(needsKind -> {
            NeedsKindVo needsKindVo = new NeedsKindVo();
            needsKindVo.setId(needsKind.getId());
            needsKindVo.setName(needsKind.getName());

            needsKindVos.add(needsKindVo);
        });

        return needsKindVos;
    }
}




